/**
 * 
 */
package com.nari.heatshare.service;

import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.commons.beanutils.BeanUtils;

import com.nari.baseinfo.dao.ICityDao;
import com.nari.baseinfo.dao.ICommunityDao;
import com.nari.baseinfo.dao.IConcentratorDao;
import com.nari.baseinfo.dao.IHeatMeterDao;
import com.nari.baseinfo.dao.IHeatRoomDao;
import com.nari.baseinfo.dao.IShareAreaDao;
import com.nari.baseinfo.model.ICommunity;
import com.nari.baseinfo.model.IHeatMeter;
import com.nari.baseinfo.model.IHeatRoom;
import com.nari.baseinfo.model.IShareArea;
import com.nari.basic.utils.sysmgr.UserRoleUtil;
import com.nari.coreframe.service.GenericServiceImpl;
import com.nari.heatshare.dao.IAssignMeterDao;
import com.nari.heatshare.dao.IAssignMeterDataGatherDao;
import com.nari.heatshare.dao.IHeatMeterDataGatherDao;
import com.nari.heatshare.dao.IShareAreaResultDao;
import com.nari.heatshare.dao.IShareSinkResultDao;
import com.nari.heatshare.dao.IUserShareResultDao;
import com.nari.heatshare.model.IAssignMeter;
import com.nari.heatshare.model.IAssignMeterDataGather;
import com.nari.heatshare.model.IShareAreaResult;
import com.nari.heatshare.model.IShareSinkResult;
import com.nari.heatshare.model.IUserShareResult;
import com.nari.heatshare.utils.AreaResultVerifyInfo;
import com.nari.platform.date.CalendarUtils;
import com.nari.platform.model.PageCond;
import com.nari.platform.model.ResponseMsg;
import com.nari.platform.model.ResultWithPageCond;
import com.nari.platform.utils.NumberSystemConversion;
import com.nari.sink.bo.PSinkInfo;
import com.nari.sink.dao.ISinkDao;

/**
 * 
 * @author Xiaopeng
 * @date 2013-8-19
 */
public class ShareAreaResultServiceImpl extends GenericServiceImpl<IShareAreaResult, String> 
		implements IShareAreaResultService {
	private String assignMeterDataQualified;
	private ICityDao iCityDao;
	private ICommunityDao iCommunityDao;
	private IShareAreaDao iShareAreaDao;
	private IHeatMeterDao iHeatMeterDao;
	private IHeatRoomDao iHeatRoomDao;
	private IHeatMeterDataGatherDao iHeatMeterDataGatherDao;
	private IAssignMeterDataGatherDao iAssignMeterDataGatherDao;
	private IAssignMeterDao iAssignMeterDao;
	private IConcentratorDao iConcentratorDao;
	private ISinkDao iSinkDao;
	private IUserShareResultDao iUserShareResultDao;
	private IShareSinkResultDao iShareSinkResultDao;

	/**
	 * 分页查询分摊域分摊结果
	 * @param projectUID 所属项目(可选)
	 * @param communityUID 所属小区(可选)
	 * @param shareAreaUID 所属分摊域(可选)
	 * @param shareName 分摊名称(可选)
	 * @param pageCond
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2013-9-4
	 */
	public ResultWithPageCond<IShareAreaResult> queryAreaResultPage(String projectUID, 
			String communityUID, String shareAreaUID, String shareName, 
			PageCond pageCond) throws Exception {
		IShareAreaResultDao iShareAreaResultDao = (IShareAreaResultDao) this.getiGenericDao();
		return iShareAreaResultDao.queryAreaResultPage(projectUID,communityUID, shareAreaUID, shareName, pageCond);
	}

	/**
	 * 通过所属关系（所属项目、所属小区、所属分摊域）查询分摊域分摊结果列表
	 * @param projectUID 所属项目(可选)
	 * @param communityUID 所属小区(可选)
	 * @param shareAreaUID 所属分摊域(可选)
	 * @return 若所属关系（所属项目、所属小区、所属分摊域）均不存在，则返回空列表
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2013-9-4
	 */
	public List<IShareAreaResult> queryAreaResultsByBelongs(String projectUID,
			String communityUID, String shareAreaUID) throws Exception {
		IShareAreaResultDao iShareAreaResultDao = (IShareAreaResultDao) this.getiGenericDao();
		return iShareAreaResultDao.queryAreaResultsByBelongs(projectUID, communityUID, shareAreaUID);
	}

	/**
	 * 通过分摊域分摊列表查询与之关联的行政机构ID-机构名称映射表
	 * @param areaResultList 分摊域分摊列表，若列表为空，则返回空的映射表
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2013-9-4
	 */
	public Map<String, String> queryReferCitysByAreaResultList(
			List<IShareAreaResult> areaResultList) throws Exception {
		List<String> cityIDList = null;
		if (areaResultList != null && areaResultList.size() > 0) {
			cityIDList = new ArrayList<String>();
			for (IShareAreaResult areaResult : areaResultList) {
				cityIDList.add(areaResult.getProvinceCityID());
				cityIDList.add(areaResult.getCapitalCityID());
				cityIDList.add(areaResult.getDistrictCityID());
			}
		}
		return iCityDao.queryIdNameMapByIDList(cityIDList);
	}

	/**
	 * 通过分摊域分摊列表查询与之关联的小区ID-小区名称映射表
	 * @param areaResultList 分摊域分摊列表，若列表为空，则返回空的映射表
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2013-9-4
	 */
	public Map<String, String> queryReferCommunitysByAreaResultList(
			List<IShareAreaResult> areaResultList) throws Exception {
		List<String> communityIDList = null;
		if (areaResultList != null && areaResultList.size() > 0) {
			communityIDList = new ArrayList<String>();
			for (IShareAreaResult areaResult : areaResultList) {
				communityIDList.add(areaResult.getCommunityID());
			}
		}
		return iCommunityDao.queryIdNameMapByIDList(communityIDList);
	}

	/**
	 * 通过分摊域分摊列表查询与之关联的分摊域ID-分摊域名称映射表
	 * @param areaResultList 分摊域分摊列表，若列表为空，则返回空的映射表
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2013-9-4
	 */
	public Map<String, String> queryReferShareAreasByAreaResultList(
			List<IShareAreaResult> areaResultList) throws Exception {
		List<String> shareAreaIDList = null;
		if (areaResultList != null && areaResultList.size() > 0) {
			shareAreaIDList = new ArrayList<String>();
			for (IShareAreaResult areaResult : areaResultList) {
				shareAreaIDList.add(areaResult.getShareAreaID());
			}
		}
		return iShareAreaDao.queryIdNameMapByIDList(shareAreaIDList);
	}

	/**
	 * 新增或修改分摊域分摊信息
	 * @param shareAreaResult
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2013-9-6
	 */
	public ResponseMsg saveOrUpdateAreaResult(IShareAreaResult shareAreaResult) throws Exception {
		// 所属分摊域
		IShareArea shareArea = this.iShareAreaDao.queryEntityById(shareAreaResult.getShareAreaID());
		// 根据平均分摊的分摊方法，修正分摊周期的起止日期
		if ("1".equals(shareAreaResult.getShareType())) {
			// 过程分摊，校验分摊周期的起止日期是否在采暖周期范围内
			if (shareAreaResult.getStartDate().getTime() < shareArea.getStartDate().getTime()
					|| shareAreaResult.getEndDate().getTime() > shareArea.getEndDate().getTime()) {
				return ResponseMsg.getInstance(false, "请确认分摊周期的起止日期是在分摊域的采暖周期范围内！");
			}
		}
		if ("2".equals(shareAreaResult.getShareType())) {
			// 收费分摊，依据采暖周期的起止日期修正分摊周期
			shareAreaResult.setStartDate(shareArea.getStartDate());
			shareAreaResult.setEndDate(shareArea.getEndDate());
		}
		// 所属小区
		ICommunity community = this.iCommunityDao.queryEntityById(shareAreaResult.getCommunityID());
		// 设置分摊结果所属城市
		shareAreaResult.setProvinceCityID(community.getProvinceCityID());
		shareAreaResult.setCapitalCityID(community.getCapitalCityID());
		shareAreaResult.setDistrictCityID(community.getDistrictCityID());
		// 保存分摊结果信息
		if (shareAreaResult.getId() != null && !"".equals(shareAreaResult.getId())) {
			this.getiGenericDao().updateEntity(shareAreaResult, shareAreaResult.getId());
		} else {
			this.getiGenericDao().saveEntity(shareAreaResult);
		}
		return ResponseMsg.getInstance(true, "");
	}
	
	/**
	 * 通过分摊域分摊ID删除分摊信息，并级联删除从属于此分摊域分摊的用户分摊，
	 * 以及用户散热器分摊结果
	 * @param areaResultUID
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2013-10-8
	 */
	public ResponseMsg deleteAreaResultBatchByUID(String areaResultUID) throws Exception {
		//删除对应的所有散热器分摊结果
		this.iShareSinkResultDao.deleteSinkResultByAreaResultUID(areaResultUID);
		//删除对应的所有用户分摊结果
		this.iUserShareResultDao.deleteUserResultByAreaResultUID(areaResultUID);
		//删除分摊域分摊结果
		this.getiGenericDao().deleteEntityById(areaResultUID);
		return ResponseMsg.getInstance(true, "");
	}
	
	/**
	 * 校验分摊域分摊的分摊条件
	 * @param areaResultUID
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2013-9-22
	 */
	public AreaResultVerifyInfo checkCalcAreaResultCondition(String areaResultUID) throws Exception {
		AreaResultVerifyInfo verifyInfo = AreaResultVerifyInfo.getInstance();
		//分摊域分摊信息
		IShareAreaResult areaResult = this.getiGenericDao().queryEntityById(areaResultUID);
		verifyInfo.setAreaResultUID(areaResult.getId());
		verifyInfo.setShareAreaUID(areaResult.getShareAreaID());
		/**	分摊域基本信息校验	**/
		IShareArea shareArea = iShareAreaDao.queryEntityById(areaResult.getShareAreaID());
		if (shareArea == null) {
			verifyInfo.setShareAreaVerify(ResponseMsg.getInstance(false, "缺少对应的分摊域信息！"));
		} else {
			String shareAreaVerify = "";
			boolean verifyFlag = true;
			if (shareArea.getBinaryPercent() < 0) {
				shareAreaVerify += "缺少对应的分摊域的二部制比例！";
				verifyFlag = false;
			} 
			if (shareArea.getMeasureChargePrice() <= 0) {
				shareAreaVerify += "缺少对应的分摊域的计量收费热价！";
				verifyFlag = false;
			} 
			if (shareArea.getAreaChargePrice() <= 0) {
				shareAreaVerify += "缺少对应的分摊域的面积收费热价！";
				verifyFlag = false;
			} 
			if(verifyFlag) {
				verifyInfo.setShareAreaVerify(ResponseMsg.getInstance(true, "对应的分摊域信息无问题！"));
			} else {
				verifyInfo.setShareAreaVerify(ResponseMsg.getInstance(false, shareAreaVerify));
			}
		}
		/**	热量表，及热量表对应的热量表数据校验	**/
		boolean heatMeterDataFlag = true;
		String heatMeterDataVerify = "";
		String heatMeterDataIDList = "";
		//热量表基本信息校验
		List<IHeatMeter> heatMeterList = iHeatMeterDao.queryMetersByBelongs(null, null, null, areaResult.getShareAreaID());
		if(heatMeterList==null || heatMeterList.size()==0) {
			heatMeterDataVerify += "缺少分摊域对应的热量表信息！";
			heatMeterDataFlag = false;
		}
		//热量表数据校验，并记录对应热量表数据校验失败的热量表表号
		String meterNoList = "";
		if(heatMeterList!=null && heatMeterList.size()>0) {
			for(int meterIndex=0; meterIndex<heatMeterList.size(); meterIndex++) {
				IHeatMeter heatMeter = heatMeterList.get(meterIndex);
				// 热量表数据完整性校验 - 对应于分摊周期起始日期的热量表数据检查
				int startMeterDataNum = iHeatMeterDataGatherDao.countMeterDatasByMeterNoAndDate(heatMeter.getMeterNo(), areaResult.getStartDate());
				if (startMeterDataNum <= 0) {
					if(heatMeterDataVerify.indexOf("缺少对应于分摊周期起始日期的热量表数据！") < 0) {
						heatMeterDataVerify += "缺少对应于分摊周期起始日期的热量表数据！";
					}
					//记录缺少数据的热量表表号
					if(meterNoList.indexOf(heatMeter.getMeterNo()) < 0) {
						meterNoList += heatMeter.getMeterNo() + ",";
					}
					heatMeterDataFlag = false;
				} 
				// 热量表数据完整性校验 - 对应于分摊周期结束日期的热量表数据检查
				int endMeterDataNum = iHeatMeterDataGatherDao.countMeterDatasByMeterNoAndDate(heatMeter.getMeterNo(), areaResult.getEndDate());
				if (endMeterDataNum <= 0) {
					if(heatMeterDataVerify.indexOf("缺少对应于分摊周期结束日期的热量表数据！") < 0) {
						heatMeterDataVerify += "缺少对应于分摊周期结束日期的热量表数据！";
					}
					//记录缺少数据的热量表表号
					if(meterNoList.indexOf(heatMeter.getMeterNo()) < 0) {
						meterNoList += heatMeter.getMeterNo() + ",";
					}
					heatMeterDataFlag = false;
				} 
			}
		}
		//校验失败的热量表数据ID列表
		if(heatMeterDataIDList.length() > 0) {
			heatMeterDataIDList = heatMeterDataIDList.substring(0, heatMeterDataIDList.length()-1);
		}
		verifyInfo.setHeatMeterDataIDList(heatMeterDataIDList);
		//校验缺少热量表数据的热量表表号列表
		if(meterNoList.length() > 0) {
			meterNoList = meterNoList.substring(0, meterNoList.length()-1);
		}
		verifyInfo.setMeterNoList(meterNoList);
		if(heatMeterDataFlag) {
			verifyInfo.setHeatMeterDataVerify(ResponseMsg.getInstance(true, "对应的热量表数据无问题！"));
		} else {
			verifyInfo.setHeatMeterDataVerify(ResponseMsg.getInstance(false, heatMeterDataVerify));
		}
		//查询分摊域下的热用户列表
		List<IHeatRoom> roomList = this.iHeatRoomDao.queryHeatRoomsByBelongs(null, null, areaResult.getShareAreaID(), null);
		/**	热用户基本信息校验，并记录校验失败的热用户ID列表	**/
		String heatRoomBaseInfoVerify = "";
		String heatRoomIDList = "";
		boolean heatRoomVerifyFlag = true;
		/**	分配表数据信息校验，并记录缺少分配表的热用户、分配表数据不合规的ID、
		  	对应缺少分配表数据的分配表表号	**/
		boolean assignMeterDataFlag = true;
		String roomOwnerList = "";
		String assignMeterDataVerify = "";
		String assignMeterDataIDList = "";
		String seriousNumList = "";
		/** 散热器信息校验，并记录缺少散热器的热用户、散热器数据不合规的ID **/
		for (int roomIndex=0; roomIndex<roomList.size(); roomIndex++) {
			IHeatRoom heatRoom = roomList.get(roomIndex);
			//热用户户修正系数校验
			if (heatRoom.getReviseFactor() < 0) {
				if(heatRoomBaseInfoVerify.indexOf("缺少用户户修正系数！") < 0) {
					heatRoomBaseInfoVerify += "缺少用户户修正系数！";
				}
				//记录不合规定的热用户ID
				heatRoomIDList += heatRoom.getId() + ",";
				heatRoomVerifyFlag = false;
			} 
			//热用户供热面积校验(若供热面积为0，可用建筑面积替代，若建筑面积也为0，则要求修正用户信息)
			if (heatRoom.getHeatArea()<=0 && heatRoom.getStructArea()<=0) {
				if(heatRoomBaseInfoVerify.indexOf("缺少用户供热面积信息！") < 0) {
					heatRoomBaseInfoVerify += "缺少用户供热面积信息！";
				}
				//记录不合规定的热用户ID
				heatRoomIDList += heatRoom.getId() + ",";
				heatRoomVerifyFlag = false;
			}
			/**	校验参与计量收费热用户的分配表，及分配表数据	**/
			if(heatRoom.getIfMeasureCharge() == 2) {
				//热用户所属的分配表
				List<IAssignMeter> meterList = iAssignMeterDao.queryAssignMetersByBelongs(null, null, null, heatRoom.getId());
				//分配表基本信息校验
				if(meterList==null || meterList.size()==0) {
					if(assignMeterDataVerify.indexOf("缺少热用户对应的分配表信息！") < 0) {
						assignMeterDataVerify += "缺少热用户对应的分配表信息！";
						//记录缺少分配表的热用户
						String roomOwner = heatRoom.getHouseNo() + "(" + heatRoom.getRoomOwner() + ")";
						if(roomOwnerList.indexOf(roomOwner) < 0) {
							roomOwnerList = roomOwner + ",";
						}
						assignMeterDataFlag = false;
					}
				} 
				//分配表数据校验
				if(meterList!=null && meterList.size() > 0) {
					for(int meterIndex=0; meterIndex<meterList.size(); meterIndex++) {
						IAssignMeter assignMeter = meterList.get(meterIndex);
						//分配表数据完整性校验 - 对应于分摊周期起始日期的分配表数据检查
						long startAssignMeterDataNum = iAssignMeterDataGatherDao.countMeterDataByCond(assignMeter.getSeriousNum(), areaResult.getStartDate());
						if(startAssignMeterDataNum <= 0) {
							if(assignMeterDataVerify.indexOf("缺少对应于分摊周期起始日期的分配表数据！") < 0) {
								assignMeterDataVerify += "缺少对应于分摊周期起始日期的分配表数据！";
							}
							//记录缺少分配表数据的分配表表号
							if(seriousNumList.indexOf(assignMeter.getSeriousNum()) < 0) {
								seriousNumList += assignMeter.getSeriousNum() + ",";
							}
							assignMeterDataFlag = false;
						} else {
							//分配表数据完整性校验 - 对应于分摊周期起始日期的分配表数据准确性检查
							IAssignMeterDataGather assignMeterData = 
									iAssignMeterDataGatherDao.queryMeterDatasByCond(assignMeter.getSeriousNum(), areaResult.getStartDate()).get(0);
							//温度范围(0~99)检查
							boolean tempRationalFlag = true;
							if(assignMeterData.getFontTemperature()<0 || assignMeterData.getFontTemperature()>99) {
								if(assignMeterDataVerify.indexOf("对应于分摊周期起始日期的分配表数据的前板温度不符合正确的温度范围(0~99)！") < 0) {
									assignMeterDataVerify += "对应于分摊周期起始日期的分配表数据的前板温度不符合正确的温度范围(0~99)！";
									tempRationalFlag = false;
								} 
							}
							if(assignMeterData.getBackTmperature()<0 || assignMeterData.getBackTmperature()>99) {
								if(assignMeterDataVerify.indexOf("对应于分摊周期起始日期的分配表数据的背板温度不符合正确的温度范围(0~99)！") < 0) {
									assignMeterDataVerify += "对应于分摊周期起始日期的分配表数据的背板温度不符合正确的温度范围(0~99)！";
									tempRationalFlag = false;
								}
							}
							//前板温度超过背板温度3度以上
							if(assignMeterData.getFontTemperature() - assignMeterData.getBackTmperature() > 3) {
								if(assignMeterDataVerify.indexOf("对应于分摊周期起始日期的分配表数据的前板温度超过了背板温度3度以上！") < 0) {
									assignMeterDataVerify += "对应于分摊周期起始日期的分配表数据的前板温度超过了背板温度3度以上！";
									tempRationalFlag = false;
								}
							}
							if(!tempRationalFlag) {
								assignMeterDataIDList += assignMeterData.getId() + ",";
								assignMeterDataFlag = false;
							}
						}
						//分配表数据完整性校验 - 对应于分摊周期结束日期的分配表数据检查
						long endAssignMeterDataNum = iAssignMeterDataGatherDao.countMeterDataByCond(assignMeter.getSeriousNum(), areaResult.getEndDate());
						if(endAssignMeterDataNum <= 0) {
							if(assignMeterDataVerify.indexOf("缺少对应于分摊周期结束日期的分配表数据！") < 0) {
								assignMeterDataVerify += "缺少对应于分摊周期结束日期的分配表数据！";
							}
							//记录缺少分配表数据的分配表表号
							if(seriousNumList.indexOf(assignMeter.getSeriousNum()) < 0) {
								seriousNumList += assignMeter.getSeriousNum() + ",";
							}
							assignMeterDataFlag = false;
						} else {
							//分配表数据完整性校验 - 对应于分摊周期结束日期的分配表数据准确性检查
							IAssignMeterDataGather assignMeterData = 
									iAssignMeterDataGatherDao.queryMeterDatasByCond(assignMeter.getSeriousNum(), areaResult.getEndDate()).get(0);
							//温度范围(0~99)检查
							boolean tempRationalFlag = true;
							if(assignMeterData.getFontTemperature()<0 || assignMeterData.getFontTemperature()>99) {
								if(assignMeterDataVerify.indexOf("对应于分摊周期结束日期的分配表数据的前板温度不符合正确的温度范围(0~99)！") < 0) {
									assignMeterDataVerify += "对应于分摊周期结束日期的分配表数据的前板温度不符合正确的温度范围(0~99)！";
									tempRationalFlag = false;
								}
							}
							if(assignMeterData.getBackTmperature()<0 || assignMeterData.getBackTmperature()>99) {
								if(assignMeterDataVerify.indexOf("对应于分摊周期结束日期的分配表数据的背板温度不符合正确的温度范围(0~99)！") < 0) {
									assignMeterDataVerify += "对应于分摊周期结束日期的分配表数据的背板温度不符合正确的温度范围(0~99)！";
									tempRationalFlag = false;
								}
							}
							//前板温度超过背板温度3度以上
							if(assignMeterData.getFontTemperature() - assignMeterData.getBackTmperature() > 3) {
								if(assignMeterDataVerify.indexOf("对应于分摊周期结束日期的分配表数据的前板温度超过了背板温度3度以上！") < 0) {
									assignMeterDataVerify += "对应于分摊周期结束日期的分配表数据的前板温度超过了背板温度3度以上！";
									tempRationalFlag = false;
								}
							}
							if(!tempRationalFlag) {
								assignMeterDataIDList += assignMeterData.getId() + ",";
								assignMeterDataFlag = false;
							}
						} //分配表数据合规性检查结束
					} //分配表列表循环结束
				} //分配表数据校验结束
			} //参与计量收费热用户信息校验结束
		} //热用户列表循环结束
		//热用户基本信息校验
		if(heatRoomIDList.length() > 0) {
			heatRoomIDList = heatRoomIDList.substring(0, heatRoomIDList.length()-1);
		}
		verifyInfo.setHeatRoomIDList(heatRoomIDList);
		if(heatRoomVerifyFlag) {
			verifyInfo.setHeatRoomVerify(ResponseMsg.getInstance(true, "对应的热用户信息无问题！"));
		} else {
			verifyInfo.setHeatRoomVerify(ResponseMsg.getInstance(false, heatRoomBaseInfoVerify));
		}
		//分配表数据校验 - 参与计量收费但缺少分配表的热用户
		if(roomOwnerList.length() > 0) {
			roomOwnerList = roomOwnerList.substring(0, roomOwnerList.length()-1);
		}
		verifyInfo.setRoomOwnerList(roomOwnerList);
		//分配表数据校验 - 缺少分配表数据，及分配表数据不合规
		if(seriousNumList.length() > 0) {
			seriousNumList = seriousNumList.substring(0, seriousNumList.length()-1);
		}
		verifyInfo.setSeriousNumList(seriousNumList);
		if(assignMeterDataIDList.length() > 0) {
			assignMeterDataIDList = assignMeterDataIDList.substring(0, assignMeterDataIDList.length()-1);
		}
		verifyInfo.setAssignMeterDataIDList(assignMeterDataIDList);
		if(assignMeterDataFlag) {
			verifyInfo.setAssignMeterDataVerify(ResponseMsg.getInstance(true, "对应的分配表数据无问题！"));
		} else {
			verifyInfo.setAssignMeterDataVerify(ResponseMsg.getInstance(false, assignMeterDataVerify));
		}
		/**	分配表数据上传率校验	**/
		//系统预定义的合规上传率
		double qualifiedUploadPercent = new BigDecimal(assignMeterDataQualified).doubleValue();
		boolean uploadPercentFlag = true;
		String assignMeterUploadPerVerify = "";
		//上传率数据校验 - 对应于分摊周期起始日期的分配表数据上传率校验
		double startUploadPercent = iAssignMeterDataGatherDao.calcUploadPercentByShareArea(areaResult.getShareAreaID(), areaResult.getStartDate());
		assignMeterUploadPerVerify += "对应于分摊周期起始日期的分配表数据上传率为" 
					+ startUploadPercent + "%";
		if(startUploadPercent < qualifiedUploadPercent) {
			assignMeterUploadPerVerify += "，不符合规定的"+qualifiedUploadPercent+"%！";
			uploadPercentFlag = false;
		} else {
			assignMeterUploadPerVerify += "！";
		}
		//上传率数据校验 - 对应于分摊周期结束日期的分配表数据上传率校验
		double endUploadPercent = iAssignMeterDataGatherDao.calcUploadPercentByShareArea(areaResult.getShareAreaID(), areaResult.getEndDate());
		assignMeterUploadPerVerify += "对应于分摊周期结束日期的分配表数据上传率为" 
					+ endUploadPercent + "%";
		if(endUploadPercent < qualifiedUploadPercent) {
			assignMeterUploadPerVerify += "，不符合规定的"+qualifiedUploadPercent+"%！";
			uploadPercentFlag = false;
		}else {
			assignMeterUploadPerVerify += "！";
		}
		if(uploadPercentFlag) {
			String uploadMsg = "对应于分摊周期起始日期的分配表数据上传率为" 
					+ startUploadPercent + "%，" 
					+ "对应于分摊周期结束日期的分配表数据上传率为"
					+ endUploadPercent + "%，"
					+ "均达到规定的" + qualifiedUploadPercent + "%！";
			verifyInfo.setAssignMeterUploadPerVerify(ResponseMsg.getInstance(true, uploadMsg));
		} else {
			verifyInfo.setAssignMeterUploadPerVerify(ResponseMsg.getInstance(false, assignMeterUploadPerVerify));
		}
		return verifyInfo;
	}

	/**
	 * 根据分摊域分摊唯一标识进行分摊计算
	 * @param areaResultUID
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2013-9-6
	 */
	public ResponseMsg saveAreaResultCalculation(String areaResultUID) throws Exception {
		// 分摊域分摊信息
		IShareAreaResult shareAreaResult = this.getiGenericDao().queryEntityById(areaResultUID);
		// 分摊域基本信息
		IShareArea shareArea = iShareAreaDao.queryEntityById(shareAreaResult.getShareAreaID());
		// 基本热价
		shareAreaResult.setBasePrice(shareArea.getBasePrice());
		// 计量热价
		shareAreaResult.setMeasureChargePrice(shareArea.getMeasureChargePrice());
		// 计量单位
		shareAreaResult.setMeasureUnit(shareArea.getMeasureUnit());
		// 格式化计量热价为[元/MWh]
		IShareAreaResultDao iShareAreaResultDao = (IShareAreaResultDao) this.getiGenericDao();
		double formatMeasurePriceMWh = iShareAreaResultDao.formatMeasureChargePriceToMWh(shareArea.getMeasureChargePrice(), shareArea.getMeasureUnit());
		// 面积热价
		shareAreaResult.setAreaChargePrice(shareArea.getAreaChargePrice());
		//面积热价修正，(分摊周期的间隔天数/采暖季的天数)×面积热价
		int heatSupplyBetweenDays = CalendarUtils.calcDaysBetweenDatesPeriod(shareArea.getStartDate(), shareArea.getEndDate()) + 1;
		int sharePeriodBetweenDays = CalendarUtils.calcDaysBetweenDatesPeriod(shareAreaResult.getStartDate(), shareAreaResult.getEndDate()) + 1;
		double areaChargePriceRevise = new BigDecimal(sharePeriodBetweenDays)
				.divide(new BigDecimal(heatSupplyBetweenDays), new MathContext(6, RoundingMode.HALF_UP))
				.multiply(new BigDecimal(shareArea.getAreaChargePrice()))
				.doubleValue();
		// 二步制比例-百分数转化为小数
		double binaryPercent = new BigDecimal(shareArea.getBinaryPercent())
				.divide(new BigDecimal(100.0))
				.doubleValue();
		//基本热价修正，基本热价修正=面积热价修正×二步制比例
		double basePriceRevise = new BigDecimal(areaChargePriceRevise)
				.multiply(new BigDecimal(binaryPercent))
				.doubleValue();
		// 总热用户数
		int heatRoomSum = this.iHeatRoomDao.countHeatRoomsByAreaUID(shareAreaResult.getShareAreaID(), null);
		shareAreaResult.setHeatRoomSum(heatRoomSum);
		// 总供热面积
		double heatAreaSum = this.iHeatRoomDao.sumRoomStructAreaByAreaUID(shareAreaResult.getShareAreaID(), null);
		shareAreaResult.setHeatAreaSum(NumberSystemConversion.toFixedDecimalScale(heatAreaSum, 3));
		// 不参与计量收费的热用户数
		int nomeasureRoomSum = this.iHeatRoomDao.countHeatRoomsByAreaUID(shareAreaResult.getShareAreaID(), 1);
		shareAreaResult.setNomeasureRoomSum(nomeasureRoomSum);
		// 不参与计量收费的总建筑面积
		double nomeasureAreaSum = this.iHeatRoomDao.sumRoomStructAreaByAreaUID(shareAreaResult.getShareAreaID(), 1);
		shareAreaResult.setNomeasureAreaSum(NumberSystemConversion.toFixedDecimalScale(nomeasureAreaSum, 3));
		//分摊域所属的计和、计差热量表列表
		List<IHeatMeter> addTypeHeatMeters = iHeatMeterDao.queryHeatMetersByAreaUID(shareAreaResult.getShareAreaID(), "add");
		List<IHeatMeter> subsTypeHeatMeters = iHeatMeterDao.queryHeatMetersByAreaUID(shareAreaResult.getShareAreaID(), "subs");
		// 对应于分摊周期起始日期、计和热量表的热量表数据
		double startAddTypeSumHeatMWh = iHeatMeterDataGatherDao.calcSumHeatByMeterListAndDate(addTypeHeatMeters, shareAreaResult.getStartDate());
		// 对应于分摊周期起始日期、计差热量表的热量表数据
		double startSubsTypeSumHeatMWh = iHeatMeterDataGatherDao.calcSumHeatByMeterListAndDate(subsTypeHeatMeters, shareAreaResult.getStartDate());
		// 对应于分摊周期起始日期累计热量
		BigDecimal startSumHeatMWh = new BigDecimal(startAddTypeSumHeatMWh).subtract(new BigDecimal(startSubsTypeSumHeatMWh));
		// 对应于分摊周期结束日期、计和热量表的热量表数据
		double endAddTypeSumHeatMWh = iHeatMeterDataGatherDao.calcSumHeatByMeterListAndDate(addTypeHeatMeters, shareAreaResult.getEndDate());
		// 对应于分摊周期结束日期、计差热量表的热量表数据
		double endSubsTypeSumHeatMWh = iHeatMeterDataGatherDao.calcSumHeatByMeterListAndDate(subsTypeHeatMeters, shareAreaResult.getEndDate());
		// 对应于分摊周期结束日期累计热量
		BigDecimal endSumHeatMWh = new BigDecimal(endAddTypeSumHeatMWh).subtract(new BigDecimal(endSubsTypeSumHeatMWh));
		//分摊域总耗热量(单位MWh)，分摊域总耗热量 = 结束日期热量表累计热量读数 - 起始日期热量表累计热量读数
		double areaHeatConsumeSum = endSumHeatMWh.subtract(startSumHeatMWh).doubleValue();
		shareAreaResult.setAreaHeatConsumeSum(NumberSystemConversion.toFixedDecimalScale(areaHeatConsumeSum, 3));
		//参与分摊用户的面积，参与分摊用户的面积 = 总供热面积 - 不参与计量收费的总供热面积
		BigDecimal partinMeasureArea = new BigDecimal(heatAreaSum)
				.subtract(new BigDecimal(nomeasureAreaSum));
		//基本热费合计，基本热费合计 = 参与计量收费或分摊用户的面积×基本热价修正
		//                         = 参与计量收费或分摊用户的面积×面积热价修正×二步制比例
		double baseHeatChargeSum = partinMeasureArea
				.multiply(new BigDecimal(basePriceRevise))
				.doubleValue();
		shareAreaResult.setBaseHeatChargeSum(NumberSystemConversion.toFixedDecimalScale(baseHeatChargeSum, 2));
		//计量热费合计，计量或分摊热费合计 = (总面积×面积热价修正×二部制比例[1] + 总耗热量×计量热价[2]) 
		//                                 - 不参与计量收费用户的面积×面积热价修正[3] 
		//                                 - 基本热费合计
		BigDecimal part1Formula = new BigDecimal(heatAreaSum)
				.multiply(new BigDecimal(areaChargePriceRevise))
				.multiply(new BigDecimal(binaryPercent));
		BigDecimal part2Formula = new BigDecimal(areaHeatConsumeSum)
				.multiply(new BigDecimal(formatMeasurePriceMWh));
		BigDecimal part3Formula = new BigDecimal(nomeasureAreaSum)
				.multiply(new BigDecimal(areaChargePriceRevise));
		double measureHeatChargeSum = part1Formula
				.add(part2Formula)
				.subtract(part3Formula)
				.subtract(new BigDecimal(baseHeatChargeSum))
				.doubleValue();
		shareAreaResult.setMeasureHeatChargeSum(NumberSystemConversion.toFixedDecimalScale(measureHeatChargeSum, 2));
		//不参与计量收费的总热费，即总面积热费
		//总面积热费 = 不参与计量收费或分摊用户的面积×面积热价修正
		double nomeasureHeatChargeSum = new BigDecimal(nomeasureAreaSum)
				.multiply(new BigDecimal(areaChargePriceRevise))
				.doubleValue();
		shareAreaResult.setNomeasureHeatChargeSum(NumberSystemConversion.toFixedDecimalScale(nomeasureHeatChargeSum, 2));
		//总热费，总热费 = 总基本热费+总分摊热费或总计量热费+总面积热费
		double totalHeatChargeSum = new BigDecimal(baseHeatChargeSum)
				.add(new BigDecimal(measureHeatChargeSum))
				.add(new BigDecimal(nomeasureHeatChargeSum))
				.doubleValue();
		shareAreaResult.setTotalHeatChargeSum(NumberSystemConversion.toFixedDecimalScale(totalHeatChargeSum, 2));
		//需要分摊的总热费，即总计量热费
		shareAreaResult.setShareHeatChargeSum(NumberSystemConversion.toFixedDecimalScale(measureHeatChargeSum, 2));
		//分摊域所属参与计量收费热用户列表
		List<IHeatRoom> roomList = iHeatRoomDao.queryHeatRoomsByAreaUID(shareAreaResult.getShareAreaID(), 2);
		//统计分摊域下各热用户散热器总权重，总权重 = ∑户散热器权重
		BigDecimal sinkWeightSum = new BigDecimal("0");
		for(IHeatRoom heatRoom: roomList) {
			double roomSinkWeight = iAssignMeterDataGatherDao.calcSinkWeightByRoomUID(heatRoom.getId(), shareAreaResult.getStartDate(), shareAreaResult.getEndDate());
			sinkWeightSum = sinkWeightSum.add(new BigDecimal(roomSinkWeight));
		}
		if(NumberSystemConversion.compareFloatValue(sinkWeightSum.doubleValue(), 0) == 0) {
			return ResponseMsg.getInstance(false, "由于所有热用户的散热器权重均为0，无法进行热费分摊；请排除异常后重新分摊计算！");
		}
		shareAreaResult.setSinkWeightSum(NumberSystemConversion.toFixedDecimalScale(sinkWeightSum.doubleValue(), 2));
		//总参考散热量，总参考散热量 = 总分摊热费或总计量热费/计量热价
		double referHeatSinkAmount = new BigDecimal(measureHeatChargeSum)
				.divide(new BigDecimal(formatMeasurePriceMWh), new MathContext(6, RoundingMode.HALF_UP))
				.doubleValue();
		shareAreaResult.setReferHeatSinkAmount(NumberSystemConversion.toFixedDecimalScale(referHeatSinkAmount, 3));
		//单位权重，单位权重 = 总参考耗热量/总权重
		double perWeight = new BigDecimal(referHeatSinkAmount)
				.divide(sinkWeightSum, new MathContext(6, RoundingMode.HALF_UP))
				.doubleValue();
		shareAreaResult.setPerWeight(NumberSystemConversion.toFixedDecimalScale(perWeight, 8));
		//本次分摊的分配表数量合计
		long assignMeterSum = iAssignMeterDao.countMeterNumByAreaUID(shareAreaResult.getShareAreaID(), 2);
		shareAreaResult.setAssignMeterSum(assignMeterSum);
		//本次分摊的散热器数量合计
		long heatSinkSum = iSinkDao.countSinkerNumByAreaUID(shareAreaResult.getShareAreaID(), 2);
		shareAreaResult.setHeatSinkSum(heatSinkSum);
		//分摊人
		shareAreaResult.setShareMan(UserRoleUtil.getSysLoginUser().getUserID());
		//分摊日期
		shareAreaResult.setShareDate(new Date());
		//设置已分摊计算
		shareAreaResult.setIfCalc(1);
		this.getiGenericDao().updateEntity(shareAreaResult, areaResultUID);
		//用户分摊计算
		ResponseMsg rmsg = this.saveUserResultCalculation(areaResultUID);
		return rmsg;
	}
	
	/**
	 * 根据分摊域分摊结果计算用户分摊
	 * @param areaResultUID
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2013-10-5
	 */
	public ResponseMsg saveUserResultCalculation(String areaResultUID) throws Exception {
		// 分摊域分摊信息
		IShareAreaResult shareAreaResult = this.getiGenericDao().queryEntityById(areaResultUID);
		//分摊域基本信息
		IShareArea shareArea = iShareAreaDao.queryEntityById(shareAreaResult.getShareAreaID());
		//格式化计量热价为[元/MWh]
		IShareAreaResultDao iShareAreaResultDao = (IShareAreaResultDao) this.getiGenericDao();
		double formatMeasurePriceMWh = iShareAreaResultDao.formatMeasureChargePriceToMWh(shareArea.getMeasureChargePrice(), shareArea.getMeasureUnit());
		//面积热价修正，(分摊周期的间隔天数/采暖季的天数)×面积热价
		int heatSupplyBetweenDays = CalendarUtils.calcDaysBetweenDatesPeriod(shareArea.getStartDate(), shareArea.getEndDate()) + 1;
		int sharePeriodBetweenDays = CalendarUtils.calcDaysBetweenDatesPeriod(shareAreaResult.getStartDate(), shareAreaResult.getEndDate()) + 1;
		double areaChargePriceRevise = new BigDecimal(sharePeriodBetweenDays)
				.divide(new BigDecimal(heatSupplyBetweenDays), new MathContext(5, RoundingMode.HALF_UP))
				.multiply(new BigDecimal(shareArea.getAreaChargePrice()))
				.doubleValue();
		// 二步制比例-百分数转化为小数
		double binaryPercent = new BigDecimal(shareArea.getBinaryPercent())
				.divide(new BigDecimal(100.0))
				.doubleValue();
		//分摊域所属的热用户
		List<IHeatRoom> roomList = iHeatRoomDao.queryHeatRoomsByAreaUID(shareAreaResult.getShareAreaID(), null);
		for(IHeatRoom heatRoom: roomList) {
			//对应于热用户的用户分摊结果
			IUserShareResult userShareResult = new IUserShareResult();
			//同步分摊域分摊信息
			userShareResult.setAreaResultID(areaResultUID);
			BeanUtils.copyProperties(userShareResult, shareAreaResult);
			//同步热用户信息
			userShareResult.setRoomId(heatRoom.getId());
			BeanUtils.copyProperties(userShareResult, heatRoom);
			//置空唯一标识，用于新增用户分摊结果
			userShareResult.setId(null);
			if(userShareResult.getIfMeasureCharge() == 2) { //参与计量收费的热用户
				//户散热器权重
				double heatSinkWeight = iAssignMeterDataGatherDao.calcSinkWeightByRoomUID(heatRoom.getId(), shareAreaResult.getStartDate(), shareAreaResult.getEndDate());
				userShareResult.setHeatSinkWeight(NumberSystemConversion.toFixedDecimalScale(heatSinkWeight, 2));
				//户基本热费，户基本热费=户建筑面积×面积热价修正×二步制比例
				double roomBaseHeatCharge = new BigDecimal(heatRoom.getStructArea())
						.multiply(new BigDecimal(areaChargePriceRevise))
						.multiply(new BigDecimal(binaryPercent))
						.doubleValue();
				userShareResult.setRoomBaseHeatCharge(NumberSystemConversion.toFixedDecimalScale(roomBaseHeatCharge, 2));
				//户计量热费或分摊热费，户计量热费=户权重*单位权重*计量热价
				double roomMeasureCharge = new BigDecimal(heatSinkWeight)
						.multiply(new BigDecimal(shareAreaResult.getPerWeight()))
						.multiply(new BigDecimal(formatMeasurePriceMWh))
						.doubleValue();
				userShareResult.setRoomMeasureCharge(NumberSystemConversion.toFixedDecimalScale(roomMeasureCharge, 2));
				//分摊比例，户分摊比例=户权重/总权重
				double sharePercent = new BigDecimal(heatSinkWeight)
						.divide(new BigDecimal(shareAreaResult.getSinkWeightSum()), new MathContext(6, RoundingMode.HALF_UP))
						.doubleValue();
				userShareResult.setSharePercent(NumberSystemConversion.toFixedDecimalScale(sharePercent, 4));
				//参与计量收费热用户的总热费，户总热费=户基本热费+户计量热费
				double totalChargeAmount = new BigDecimal(roomBaseHeatCharge)
						.add(new BigDecimal(roomMeasureCharge))
						.doubleValue();
				userShareResult.setTotalChargeAmount(NumberSystemConversion.toFixedDecimalScale(totalChargeAmount, 2));
				//户参考散热量，户参考耗热量 = 户分摊比例×总参考耗热量
				//                         = 户权重/总权重×总参考耗热量
				double referHeatConsume = new BigDecimal(heatSinkWeight)
						.divide(new BigDecimal(shareAreaResult.getSinkWeightSum()), new MathContext(6, RoundingMode.HALF_UP))
						.multiply(new BigDecimal(shareAreaResult.getReferHeatSinkAmount()))
						.doubleValue();
				userShareResult.setReferHeatConsume(NumberSystemConversion.toFixedDecimalScale(referHeatConsume, 5));
				//户面积热费，户面积热费 = 户建筑面积×面积热价修正
				double roomAreaCharge = new BigDecimal(heatRoom.getStructArea())
						.multiply(new BigDecimal(areaChargePriceRevise))
						.doubleValue();
				userShareResult.setRoomAreaCharge(NumberSystemConversion.toFixedDecimalScale(roomAreaCharge, 2));
				//差额，差额 =户面积热费—参与分摊热用户的总热费
				double balanceAmount = new BigDecimal(roomAreaCharge)
						.subtract(new BigDecimal(totalChargeAmount))
						.doubleValue();
				userShareResult.setBalanceAmount(NumberSystemConversion.toFixedDecimalScale(balanceAmount, 2));
			} else { //不参与计量收费的热用户
				//户面积热费，户面积热费 = 户建筑面积×面积热价修正
				double roomAreaCharge = new BigDecimal(heatRoom.getStructArea())
						.multiply(new BigDecimal(areaChargePriceRevise))
						.doubleValue();
				userShareResult.setRoomAreaCharge(NumberSystemConversion.toFixedDecimalScale(roomAreaCharge, 2));
				//不参与计量收费热用户的总热费，即户面积热费
				userShareResult.setTotalChargeAmount(NumberSystemConversion.toFixedDecimalScale(roomAreaCharge, 2));
			}
			//散热器数量合计
			long totalSinkAmount = iSinkDao.countSinkerNumByRoomUID(heatRoom.getId());
			userShareResult.setTotalSinkAmount(new Long(totalSinkAmount).intValue());
			//保存用户分摊结果
			String userResultUID = this.iUserShareResultDao.saveEntity(userShareResult);
			//分析计算用户分摊对应的散热器信息
			this.saveShareSinkCalculation(areaResultUID, userResultUID);
		}
		return ResponseMsg.getInstance(true, "");
	}
	
	/**
	 * 分析计算用户分摊对应的所有散热器信息
	 * @param areaResultUID 分摊域分摊结果
	 * @param userResultUID 用户分摊结果
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2013-10-6
	 */
	public void saveShareSinkCalculation(String areaResultUID, 
			String userResultUID) throws Exception {
		// 分摊域分摊信息
		IShareAreaResult shareAreaResult = this.getiGenericDao().queryEntityById(areaResultUID);
		//用户分摊信息
		IUserShareResult userShareResult = iUserShareResultDao.queryEntityById(userResultUID);
		//热用户信息
		IHeatRoom heatRoom = iHeatRoomDao.queryEntityById(userShareResult.getRoomId());
		//计算参与计量收费热用户的散热器分摊信息
		if(heatRoom.getIfMeasureCharge() == 2) {
			//格式化计量热价为[元/MWh]
			IShareAreaResultDao iShareAreaResultDao = (IShareAreaResultDao) this.getiGenericDao();
			double formatMeasurePriceMWh = iShareAreaResultDao.formatMeasureChargePriceToMWh(shareAreaResult.getMeasureChargePrice(), shareAreaResult.getMeasureUnit());
			//热用户所属的散热器列表
			List<PSinkInfo> sinkList = iSinkDao.querySinkerListByBelongs(null, null, null, heatRoom.getId());
			for(PSinkInfo heatSinker: sinkList) {
				//构造用户分摊对应的散热器信息
				IShareSinkResult shareSinkResult = new IShareSinkResult();
				shareSinkResult.setUserShareResultID(userResultUID);
				shareSinkResult.setSinkNo(heatSinker.getSinkNo());
				shareSinkResult.setKqFactor(heatSinker.getKqFactor());
				shareSinkResult.setKtFactor(heatSinker.getKtFactor());
				shareSinkResult.setKcFactor(heatSinker.getKcFactor());
				//散热器评价系数K
				double kFactor = iSinkDao.calcSinkEvaluateFactor(heatSinker.getId());
				shareSinkResult.setKfactor(NumberSystemConversion.toFixedDecimalScale(kFactor, 3));
				//散热器对应的分配表
				IAssignMeter assignMeter = iAssignMeterDao.queryMeterBySinkUID(heatSinker.getId());
				//抄表日期起始日期对应的分配表数据
				IAssignMeterDataGather startMeterData = iAssignMeterDataGatherDao.queryMeterDatasByMeterUID(assignMeter.getId(), userShareResult.getStartDate()).get(0);
				//抄表日期结束日期对应的分配表数据
				IAssignMeterDataGather endMeterData = iAssignMeterDataGatherDao.queryMeterDatasByMeterUID(assignMeter.getId(), userShareResult.getEndDate()).get(0);
				//分配表读数 = 抄表日期结束日期对应的分配表数据 - 抄表日期起始日期对应的分配表数据
				double readNum = new BigDecimal(endMeterData.getReadNum())
						.subtract(new BigDecimal(startMeterData.getReadNum()))
						.doubleValue();
				shareSinkResult.setReadNum(NumberSystemConversion.toFixedDecimalScale(readNum, 2));
				//散热器权重
				double heatSinkWeight = iAssignMeterDataGatherDao.calcSinkWeightByAssignMeterUID(assignMeter.getId(), heatRoom.getReviseFactor(), userShareResult.getStartDate(), userShareResult.getEndDate());
				shareSinkResult.setHeatSinkWeight(NumberSystemConversion.toFixedDecimalScale(heatSinkWeight, 2));
				//散热器分摊比例，散热器分摊比例=散热器权重/总权重
				double sharePercent = new BigDecimal(heatSinkWeight)
						.divide(new BigDecimal(shareAreaResult.getSinkWeightSum()), new MathContext(6, RoundingMode.HALF_UP))
						.doubleValue();
				shareSinkResult.setSharePercent(NumberSystemConversion.toFixedDecimalScale(sharePercent, 5));
				//散热器分摊热费，散热器分摊热费 = 散热器权重*单位权重*计量热价
				double shareChargeAmount = new BigDecimal(heatSinkWeight)
						.multiply(new BigDecimal(shareAreaResult.getPerWeight()))
						.multiply(new BigDecimal(formatMeasurePriceMWh))
						.doubleValue();
				shareSinkResult.setShareChargeAmount(NumberSystemConversion.toFixedDecimalScale(shareChargeAmount, 2));
				//散热器参考散热量，散热器参考散热量 = 散热器分摊比例×总参考散热量
				//                                 = 散热器权重/总权重×总参考散热量
				double referHeatSinkAmount = new BigDecimal(heatSinkWeight)
						.divide(new BigDecimal(shareAreaResult.getSinkWeightSum()), new MathContext(6, RoundingMode.HALF_UP))
						.multiply(new BigDecimal(shareAreaResult.getReferHeatSinkAmount()))
						.doubleValue();
				shareSinkResult.setReferHeatSinkAmount(NumberSystemConversion.toFixedDecimalScale(referHeatSinkAmount, 3));
				//保存散热器分摊信息
				this.iShareSinkResultDao.saveEntity(shareSinkResult);
			}
		}
	}
	
	/**
	 * @return the assignMeterDataQualified
	 */
	public String getAssignMeterDataQualified() {
		return assignMeterDataQualified;
	}

	/**
	 * @param assignMeterDataQualified the assignMeterDataQualified to set
	 */
	public void setAssignMeterDataQualified(String assignMeterDataQualified) {
		this.assignMeterDataQualified = assignMeterDataQualified;
	}

	/**
	 * @return the iCityDao
	 */
	public ICityDao getiCityDao() {
		return iCityDao;
	}

	/**
	 * @param iCityDao
	 *            the iCityDao to set
	 */
	public void setiCityDao(ICityDao iCityDao) {
		this.iCityDao = iCityDao;
	}

	/**
	 * @return the iCommunityDao
	 */
	public ICommunityDao getiCommunityDao() {
		return iCommunityDao;
	}

	/**
	 * @param iCommunityDao
	 *            the iCommunityDao to set
	 */
	public void setiCommunityDao(ICommunityDao iCommunityDao) {
		this.iCommunityDao = iCommunityDao;
	}

	/**
	 * @return the iShareAreaDao
	 */
	public IShareAreaDao getiShareAreaDao() {
		return iShareAreaDao;
	}

	/**
	 * @param iShareAreaDao
	 *            the iShareAreaDao to set
	 */
	public void setiShareAreaDao(IShareAreaDao iShareAreaDao) {
		this.iShareAreaDao = iShareAreaDao;
	}

	/**
	 * @return the iHeatMeterDao
	 */
	public IHeatMeterDao getiHeatMeterDao() {
		return iHeatMeterDao;
	}

	/**
	 * @param iHeatMeterDao the iHeatMeterDao to set
	 */
	public void setiHeatMeterDao(IHeatMeterDao iHeatMeterDao) {
		this.iHeatMeterDao = iHeatMeterDao;
	}

	/**
	 * @return the iHeatRoomDao
	 */
	public IHeatRoomDao getiHeatRoomDao() {
		return iHeatRoomDao;
	}

	/**
	 * @param iHeatRoomDao
	 *            the iHeatRoomDao to set
	 */
	public void setiHeatRoomDao(IHeatRoomDao iHeatRoomDao) {
		this.iHeatRoomDao = iHeatRoomDao;
	}

	/**
	 * @return the iHeatMeterDataGatherDao
	 */
	public IHeatMeterDataGatherDao getiHeatMeterDataGatherDao() {
		return iHeatMeterDataGatherDao;
	}

	/**
	 * @param iHeatMeterDataGatherDao
	 *            the iHeatMeterDataGatherDao to set
	 */
	public void setiHeatMeterDataGatherDao(
			IHeatMeterDataGatherDao iHeatMeterDataGatherDao) {
		this.iHeatMeterDataGatherDao = iHeatMeterDataGatherDao;
	}

	public IAssignMeterDataGatherDao getiAssignMeterDataGatherDao() {
		return iAssignMeterDataGatherDao;
	}

	public void setiAssignMeterDataGatherDao(
			IAssignMeterDataGatherDao iAssignMeterDataGatherDao) {
		this.iAssignMeterDataGatherDao = iAssignMeterDataGatherDao;
	}

	public IAssignMeterDao getiAssignMeterDao() {
		return iAssignMeterDao;
	}

	public void setiAssignMeterDao(IAssignMeterDao iAssignMeterDao) {
		this.iAssignMeterDao = iAssignMeterDao;
	}

	public IConcentratorDao getiConcentratorDao() {
		return iConcentratorDao;
	}

	public void setiConcentratorDao(IConcentratorDao iConcentratorDao) {
		this.iConcentratorDao = iConcentratorDao;
	}

	/**
	 * @return the iSinkDao
	 */
	public ISinkDao getiSinkDao() {
		return iSinkDao;
	}

	/**
	 * @param iSinkDao the iSinkDao to set
	 */
	public void setiSinkDao(ISinkDao iSinkDao) {
		this.iSinkDao = iSinkDao;
	}

	/**
	 * @return the iUserShareResultDao
	 */
	public IUserShareResultDao getiUserShareResultDao() {
		return iUserShareResultDao;
	}

	/**
	 * @param iUserShareResultDao the iUserShareResultDao to set
	 */
	public void setiUserShareResultDao(IUserShareResultDao iUserShareResultDao) {
		this.iUserShareResultDao = iUserShareResultDao;
	}

	/**
	 * @return the iShareSinkResultDao
	 */
	public IShareSinkResultDao getiShareSinkResultDao() {
		return iShareSinkResultDao;
	}

	/**
	 * @param iShareSinkResultDao the iShareSinkResultDao to set
	 */
	public void setiShareSinkResultDao(IShareSinkResultDao iShareSinkResultDao) {
		this.iShareSinkResultDao = iShareSinkResultDao;
	}

}
